//
//  UserInfo.swift
//  WBSwift
//
//  Created by 贺瑞 on 2017/8/3.
//  Copyright © 2017年 herui. All rights reserved.
//

import UIKit

class UserInfo: BaseModel {
    
    //整数形用户UID
    var id : Int64 = 0
    
    //字符串型的用户UID
    var idstr : String?
    
    //用户昵称
    var screen_name : String?

    //用户头像地址（大图），180×180像素
    var avatar_large : String?

    //性别，m：男、f：女、n：未知
    var gender : String?

    //token失效期
    var expiresDate : TimeInterval = 0.0
    var accessToken : String?

    
    //判断是否登录&失效
    var isLogin : Bool {
        return Date().timeIntervalSince1970 < self.expiresDate
    }
    
    //MARK: 用户信息持久化
    static var filePath : String {
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        return (path as NSString).appendingPathComponent("userinfo.plist")
    }
    
    func save() {
        NSKeyedArchiver.archiveRootObject(self, toFile:UserInfo.filePath)
    }
    
    static func userInfo() -> UserInfo? {
        return (NSKeyedUnarchiver.unarchiveObject(withFile: filePath)) as? UserInfo
    }

}



